
package ${servicePackage!}.impl;

import cn.roin.msf.mapper.MyBatisBaseDao;
import cn.roin.msf.service.impl.BaseServiceImpl;
import cn.roin.msf.util.StringUtils;
import cn.roin.msf.dto.PageInfo;
import cn.roin.msf.dto.Pageable;
import ${servicePackage!}.${modelName!}Service;
import ${modelFullName!};
import ${modelFullName!}Example;
import ${serviceConfig.mapperFullName!};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ${module!}-ServiceImpl
 * @author ${author!}
 * @date ${.now}
 */
@Service
public class ${modelName!}ServiceImpl extends BaseServiceImpl<${modelName!},Long, ${modelName!}Example> implements ${modelName!}Service {
    @Autowired
    ${serviceConfig.mapperName!} ${serviceConfig.mapperHumpName!};
    @Override
    protected MyBatisBaseDao<${modelName!}, Long, ${modelName!}Example> getDao() {
        return ${serviceConfig.mapperHumpName!};
    }

    /**
     * 分页查询
     * @param pageable 查询参数封装类实体
     * @return
     */
    @Override
    public PageInfo<${modelName!}> getPage(Pageable pageable){
        ${modelName!}Example example = new ${modelName!}Example();
        //example.setOrderByClause("operate_time desc");//排序
        ${modelName!}Example.Criteria criteria = null;
        if (pageable==null)
            pageable = new Pageable();
        else
            criteria = example.createCriteria();
        <#if htmlConfig.columns??>
            <#assign index_=0>
            <#assign index__=1>
            <#list htmlConfig.columns as column>
                <#if column.filterColumn>
                    <#if column.filterType=='text'>
        if (!StringUtils.isEmpty(pageable.getStrVal<#if index_!= 0>${index_}</#if>())){
            criteria.and${column.field?cap_first}Like(pageable.getStrVal<#if index_!= 0>${index_}</#if>()+"%");
        }
                        <#assign index_++>
                    <#elseif column.filterType=='select'>
        if (!StringUtils.isEmpty(pageable.getStrVal<#if index_!= 0>${index_}</#if>())){
            criteria.and${column.field?cap_first}EqualTo(pageable.getStrVal<#if index_!= 0>${index_}</#if>());
        }
                        <#assign index_++>
                    <#elseif column.filterType=='date' >
        if (pageable.getDate${index__}()!=null)){
            criteria.and${column.field?cap_first}EqualTo(pageable.getDate${index__}());
        }
                        <#assign index__++>
                    <#elseif column.filterType=='date-range' >
        if (pageable.getDate${index__}()!=null && pageable.getDate${index__}end()!=null){
            criteria.and${column.field?cap_first}Between(pageable.getDate${index__}(), pageable.getDate${index__}end());
        }
        else if(pageable.getDate${index__}()!=null){
            criteria.and${column.field?cap_first}GreaterThanOrEqualTo(pageable.getDate${index__}());
        }
        else if(pageable.getDate${index__}end()!=null){
            criteria.and${column.field?cap_first}LessThanOrEqualTo(pageable.getDate${index__}end());
        }
                        <#assign index__++>
                    </#if>
                </#if>
            </#list>
        </#if>
        return getPageByExample(pageable,example);
    }

}
